<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="head.jsp"%>
<%@taglib prefix="epgutils" uri="http://chances.com.cn/jsp/epgutils" %>
<%@page import="java.util.Date"%>

<!-- 查询搜索结果分类栏目 -->
<epgdata:bizList var="search_menu_biz" code="${_templateParams['search_menu_biz']}"/>
<!-- 热门搜索 -->
<epgdata:bizList var="search_hot_biz" code="${_templateParams['search_hot_biz']}" size="20"/>
<c:set var="searchHotJson" value="${epgutils:tojson(search_hot_biz)}"/>
<!DOCTYPE html>
<html>
<head>
	<title>SMART_TV</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">	
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	<%@include file="/sites/weixin/js/common.jsp" %>
	<%@include file="/sites/weixin/common/common_js.jsp" %>
	<link rel="stylesheet" type="text/css" href="${_contextPath}/sites/weixin/css/mobile_z.css" />
	<link rel="stylesheet" type="text/css" href="${_contextPath}/sites/weixin/css/wx.css" />
	<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	<epgutils:currUrl var="cUrl"/>
	<epgutils:wechatConfig debug="true" apiString="scanQRCode" var="tokenConfig" url="${cUrl}"/>
	<script type="text/javascript" src="${_contextPath}/sites/weixin/js/iscroll.js"></script>
	<style>
	.swiper-slide {
		width: auto;
		display: inline;
		margin-right: 6%;
		height: 100%;
		padding-bottom: 0px;
	}
	</style>
<script>



function search(){
	//var text = idE("inputText").innerText;
	var text = document.getElementById("inputText").value;
	if(!strExist(text)){
		$("#alertDiv").show();
		setTimeout(function(){
			$("#alertDiv").hide();
		},800);
		return;
	}
	$("#inputBg").hide();
	$("#content").remove();
	$("#scroll_menu_swiper").css("height","2.8em");
	changeCssMenu(CurrentLiveTypeId);
	var initals = text;
	initals = initals.substring(0,8);
	saveSearchHistory(initals);
	params.initals = initals;
	//info.tagString = tagString;
	setTimeout(function(){
		if(initStatus){
			initTs();
		}else{
			getData();
		}
	},100);
}
var initStatus = true;
function initTs(){
	ts.init();
	ts.load();
	ts.newRefresh();
	initStatus = false;
	
	
	
}

function startRecord(){
	console.log("startRecord:")
	
	document.getElementById("stopRecord").style.display= "block";

    //appendText("开始录音");
    wx.startRecord();

     wx.onVoiceRecordEnd({
	     // 录音时间超过一分钟没有停止的时候会执行 complete 回调
	     complete: function (res) {
		   	 document.getElementById("stopRecord").style.display= "none";
		     var localId = res.localId;
		     handleLocalId(localId);
	     }
     });

}
function stopRecord(){
    //appendText("停止录音");
	document.getElementById("stopRecord").style.display= "none";
    
    wx.stopRecord({
        success: function (res) {
            var localId = res.localId;
            handleLocalId(localId);
        }
    });
}

function handleLocalId(localId){
    //appendText("获取localId");

    wx.translateVoice({
        localId: localId, // 需要识别的音频的本地Id，由录音相关接口获得
        isShowProgressTips: 1, // 默认为1，显示进度提示
        success: function (res) {
            // alert(res.translateResult); // 语音识别的结果
            let text = res.translateResult;
            handleText(text);
        }
     });
}
function handleText(text){
    console.log("语音文本："+text);
    // let divText = document.getElementById("text");
    // divText.innerHTML = divText.innerText+"语音文件："+text;
    //appendText("语音文本："+text);
    if(text){
	    text = text.replace("。","");
	    text = $.trim(text);
	    document.getElementById("inputText").value= text;
	    
	    search();	
    }else{
    	alert("请再说一次");
    }
}

function appendText(text){
    let divText = document.getElementById("text");
    divText.innerHTML = divText.innerText+"<br/>"+text
}

function saveSearchHistory(contentCode){
	if(contentCode == "")return;
	
	//var content = new EpgContent('search',contentCode,'','','');
	var content = new EpgCollection(contentCode,'','','','','','');
	searchStorage.add(content);
}

function deleteHistory(){
	cancel();
}
function playLog(type, contentCode, epiNum) {
	var path = "${contextPath}/searchLog.do";
	var tags = info.tags;
	if(tags == "") {
		tags = "全部";
	}
	$.ajax({
			type:"POST",
			url:path,
		    async:false,
		    data:{initals:info.initals,tags:tags,type:type,code:contentCode,epiIndex:epiNum},
			dataType:"json",
			success:"",
			failure:""
		}
	)
}
var CurrentLiveTypeId = "1";
function changeCssMenu(typeId){
	$("#liveType_"+CurrentLiveTypeId).removeClass().addClass("inner-search").addClass("category");
	CurrentLiveTypeId = typeId;
	$("#liveType_"+CurrentLiveTypeId).removeClass().addClass("inner-search-fcs");
	$("#liveType_"+CurrentLiveTypeId).addClass("category");
}
function chooseLiveType(typeId,title){
	//info.categoryCode = categoryCode;
	vm.content = [];
	ts.hideEmpty();
	changeCssMenu(typeId);
	
	if(title.indexOf("全部") != -1){
		title = "";
	}
	//当点击其它时，要传tagString
	params.tagString = "";
	if(title.indexOf("其他") != -1){
		title = "";
		params.tagString = tagString;
	}
	params.type = title;
	setTimeout(getData,200);
}
function clearText(obj){
	if(obj.placeholder == '请输入搜索关键字'){
		obj.placeholder = '';
	}
	$("#inputBg").show();
}
function showPlaceHolder(obj){
	$("#inputBg").hide();
	if(obj.value == ''){
		obj.placeholder = '请输入搜索关键字';
	}
	$("#inputBg").hide();
}
</script>
</head>
<body onload="init()">
	

	<!-- <div style="width:100%;height:100%;color:yellow;z-index:99999999999999999999999"></div> -->
	<div class="row menu-row navbar-fixed-top">
		<div class="col-xs-2 menu-col" onclick="onBackEvent();">
			<a onclick="onBackEvent();"><img src="${_templatePath}/images/back.png" class="menu-col-back" /></a>
		</div>
		<div class="col-xs-6 menu-col" style="margin-top: 5px; padding: 0px;">
			<input type="text" id="inputText" class="form-control"
				placeholder="请输入搜索关键字"
				onfocus="clearText(this);"
				onblur="showPlaceHolder(this);"
				style="width: 100%; font-size: 0.7em; height: 30px;" />
		</div>
		<div class="col-xs-2 menu-col" style="font-size:1.2em;line-height:2.8em" onclick="startRecord()">			
			<span class="glyphicon glyphicon-ice-lolly"></span>
		</div>
		<div class="col-xs-2 menu-col" style="font-size:1.2em;line-height:2.8em" onclick="search()">
			<span>搜索</span>
		</div>
	</div>
	<!-- 搜索结果分类 -->
	<epgdata:bizList var="menuCat" code="${_templateParams['search_menu_biz']}" />
	<div id="menu" class="navbar-fixed-top" style="margin-top:3.5em;">
	<div  id="scroll_menu_swiper"  class="swiper-container " style="background-color: #f2f1f1;height:0px;" >
		<div id="scroll_menu"  class="swiper-wrapper" style="margin-left:2%;">
			<c:forEach items="${menuCat}" var="item" varStatus="i">
				<input type="hidden" id="liveType_title_${i.index+1}" value="${item.title}"/>
				<div class="swiper-slide" style="height: 3em;background-color: #f2f1f1;">
					<div  id="liveType_${i.index+1}" class="category inner-search" 
						onclick="chooseLiveType('${i.index+1}','${item.title}')">${item.title}</div>
				</div>
			</c:forEach>
		</div>
	</div>
	<!-- <div id="menu_result"></div> -->
	</div>
	<script>
		$(document).ready(function(){
			   var names = ["#scroll_menu_swiper"];
		   		$.each(names,function(i,val){
		   			 var swiper1 = new Swiper(val, {
		    			  	 slidesPerView: 'auto',
		   				 });
		   		});
		   });
	</script>
	<!-- 搜索结果 -->
	<div id="app">	
	<div class="layout" id="classify_video">
		<div class="list" id="wrapper"
			style="overflow: hidden;margin-top: 6.5em;padding-top: 0em;">
			<div class="program program-list" >
				<div id="pullDown" class="" style="display: none;">
					<span class="pullDownIcon"></span><span class="pullDownLabel">往下拉刷新...</span>
				</div>
				<div class="row row-empty"></div>
				<div id="filter_result" class="row row-content">
					<template v-for="(item,index) in content">
						<div v-if="item.type == 'vod' " class="row row-empty" style="margin-bottom:10px;">
							<div class="col-xs-4" style="padding:0px;" @click="gotoDetail(item.type,item.contentCode)">
								<img class="lazyImg content-image" v-bind:src="contextPath+'/sites/weixin/images/defaultBg_2.jpg'" v-bind:data-original="resourcePath+''+item.poster"/>
							</div>
							<div class="col-xs-8 col-content">
								<div class="two-line"><span style="font-size: 1.1em;color:black;" v-text="item.title"></span></div>
								<div class="detail-text"><span>类型：</span><span style="color:#aaaaaa" v-text="item.opImg2"></span></div>
								<div class="detail-text"><span>导演：</span><span style="color:#aaaaaa" v-text="item.director"></span></div>
								<div class="two-line"><span style="color:#000;">主演：</span><span v-text="item.actors"></span></div>
								<div style="float:right; margin-top: 23px;" v-on:click="toPlay('vod',item.contentCode,'',item.title,item.poster)">
									<img style="max-width:70px;" :src="contextPath+'/sites/weixin/images/tvshow.png'"/>
								</div>
							</div>
						</div>
						<template v-if="item.type == 'series'">
							<div class="row row-empty" style="margin-bottom:10px;">
								<div class="col-xs-4" style="padding:0px;" @click="gotoDetail(item.type,item.contentCode)">
									<img class="lazyImg content-image" :src="contextPath+'/sites/weixin/images/defaultBg_2.jpg'" v-bind:data-original="resourcePath+''+item.poster"/>
								</div>
								<div class="col-xs-8 col-content">
									<div class="two-line"><span style="font-size: 1.1em;color:black;" v-text="item.title"></span></div>
									<div class="detail-text"><span>类型：</span><span style="color:#aaaaaa" v-text="item.opImg2"></span></div>
									<div class="detail-text"><span>导演：</span><span style="color:#aaaaaa" v-text="item.director"></span></div>
									<div class="two-line"><span style="color:#000;">主演：</span><span v-text="item.actors"></span></div>
									<div v-on:click="toPlay('series',item.episodes[0].contentCode,item.contentCode,item.episodes[0].contentTitle,item.poster,item.contentCode+'_1','col-xs-5ths-ep');" style="float:right; margin-top: 23px;" ><img style="max-width:70px;" :src="contextPath+'/sites/weixin/images/tvshow.png'"/></div>
								</div>
							</div>
							<div :id="'jishu_'+index">
								<template v-if="item.episodes.length > 10">
									<div class="row" style="margin-top:6px;margin-left:0px;margin-right:0px;text-align: -webkit-center;">
									<template v-for="n in 5">
										<div v-if="n == 5" v-on:click="showAll('jishu_'+index,item.contentCode+'');" class="col-xs-5ths-ep">..</div>
										<div v-if="n != 5" v-on:click="toPlay('series',item.episodes[n-1].contentCode,item.contentCode,item.episodes[n-1].contentTitle,item.poster,item.contentCode+'_'+n,'col-xs-5ths-ep');" class="col-xs-5ths-ep" :id="item.contentCode+'_'+n" v-text="item.episodes[n-1].episodeIndex"></div>
									</template>
									<template v-for="n in item.episodes.length">
										<div v-if="n > (item.episodes.length -5)" v-on:click="toPlay('series',item.episodes[n-1].contentCode,item.contentCode,item.episodes[n-1].contentTitle,item.poster,item.contentCode+'_'+n,'col-xs-5ths-ep');" class="col-xs-5ths-ep" :id="item.contentCode+'_'+n" v-text="item.episodes[n-1].episodeIndex"></div>
									</template>
								</template>
								<template v-if="item.episodes.length <= 10">
									<div class="row" style="margin-top:6px;margin-left:0px;margin-right:0px;text-align: -webkit-center;">
									<template v-for="n in item.episodes.length">
										<div v-on:click="toPlay('series',item.episodes[n-1].contentCode,item.contentCode,item.episodes[n-1].contentTitle,item.poster,item.contentCode+'_'+n,'col-xs-5ths-ep');" class="col-xs-5ths-ep" :id="item.contentCode+'_'+n" v-text="item.episodes[n-1].episodeIndex"></div>
									</template>
									</div>
								</template>
							</div>
							<div :id="'jishu_'+index+'_all'" style="display:none">
								<template v-if="item.episodes.length > 10">
									<div class="row" style="margin-top:6px;margin-left:0px;margin-right:0px; text-align: -webkit-center;">
									<template v-for="n in item.episodes.length">
										<div v-on:click="toPlay('series',item.episodes[n-1].contentCode,item.contentCode,item.episodes[n-1].contentTitle,item.poster,item.contentCode+'_'+n,'col-xs-5ths-ep');" class="col-xs-5ths-ep" :id="item.contentCode+'_'+n" v-text="item.episodes[n-1].episodeIndex"></div>
									</template>
									</div>
								</template>
							</div>
						</template>
						
						<template v-if="item.type == 'series2'">
							<div class="row row-empty" style="margin-bottom:10px;">
								<div class="col-xs-4" style="padding:0px;" @click="gotoDetail(item.type,item.contentCode)">
									<img class="lazyImg content-image" :src="contextPath+'/sites/weixin/images/defaultBg_3.jpg'"
										:data-original="resourcePath+''+item.still"/>
								</div>
								<div class="col-xs-8 col-content">
										<div class="two-line"><span style="font-size: 1.1em;color:#000;" v-text="item.title"></span></div>
										<div class="detail-text"><span>主持人：</span><span style="color:#aaaaaa" v-text="item.compere"></span></div>
										<!-- <div class="two-line"><span style="color:#000;">主演：</span v-text="item.actors"><span></span></div> -->
										<div @click="toPlay('series2',item.episodes[0].contentCode,item.contentCode,item.episodes[0].contentTitle,item.poster,item.contentCode+'_1_zy','search-zongyi');"
											style="float:right; margin-top: 23px;" ><img style="max-width:70px;" :src="contextPath+'/sites/weixin/images/tvshow.png'"/></div>
								</div>
							</div>
							<template v-if="item.episodes != null">
								<template v-for="n in item.episodes.length">
									<div v-if="n < 4" :id="item.contentCode+'_'+n+'_zy'" class="search-zongyi"
										@click="toPlay('series2',item.episodes[n-1].contentCode,item.contentCode,item.episodes[n-1].contentTitle,item.poster,item.contentCode+'_'+n+'_zy','search-zongyi');"
										v-text="getDate(item.episodes[n-1].issueDate,'')+'期: '+item.episodes[n-1].contentTitle">
									</div>
								</template>
							</template>
						</template>
						<div class="index-line" style="height:2px;margin-bottom:10px"></div>
					</template>
				</div>
				<div id="pullUp" class="" style="display: none;">
					<span class="pullUpIcon"></span><span class="pullUpLabel">往上拉加载更多...</span>
				</div>
				<div id="emptyDiv" class="empty-div" style="display: none;">
					很遗憾，未找到你需要的节目</div>
			</div>
		</div>
	</div>
	</div>
	<!--end layout-->

	<!-- 删除确认框 -->
	<div class="modal" id="mymodal" style="margin-top: 100px;">
		<div class="modal-dialog" align="center">
			<div class="modal-content" style="width: 80%;">
				<div class="row" style="margin: 0px;">
					<img class="col-schedule-image" src="${_templatePath}/images/delWin.png"/>
					<div  style="font-size:1em;position:absolute;top:30%;width:100%;text-align:center;">
						请确认是否需要删除这些信息
					</div>
					<div onclick="cancel();" style="position:absolute; left:0px;top:68%;width:50%;height:32%;">
					</div>
					<div onclick="submit();" style="position:absolute; left:50%;top:68%;width:50%;height:32%;">
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<div id="content" style="margin-top:3.5em;">
		<div class="container-fluid row-content" style="color: #aaaaaa;margin-left:6%;margin-right:6%;padding:0px;">
			<div class="row " id="history_top"
				style="margin-top: 10px; margin-left: 0px; font-size: 1.3em; color: #16a3b7">
				<div class="col-xs-10" style="padding: 0px;">
					历史搜索
				</div>
				<div id="del" class="col-xs-1" onclick="deleteHistory()">
					<span id="deleteIcon" style="color: #16a3b7"
						class="glyphicon glyphicon-trash"></span>
				</div>
			</div>
			<div id="history_line"class="index-line" style="height:0.1em;margin-top:1em;"></div>
			<div id="history" class="row">
			</div>

			<div class="row search-head">热门搜索 </div>
			<div class="index-line" style="height:0.1em;margin-top:0em;"></div>
			<div id="hotCat" class="row">
			</div>	
		</div>
	</div>
	
	<!-- 输入时蒙版 -->
	<!-- <div id="inputBg" style="position:absolute;left:0px;top:0.01em;display:none; opacity: 0.5; width:100%;height:100%;background-color: #000"> -->
	<div class="navbar-fixed-top" id="inputBg" style="display:none; opacity: 0.5; width:100%;height:100%;margin-top:3.5em;background-color: #000">
	</div>
	
	<!-- 输入时蒙版 -->
	<!-- <div id="inputBg" style="position:absolute;left:0px;top:0.01em;display:none; opacity: 0.5; width:100%;height:100%;background-color: #000"> -->
	
	<div id="stopRecord" style="display:none;">
	<div  class="navbar-fixed-top" id="speak" style="opacity: 0.5; width:100%;height:100%;margin-top:3.5em;background-color: #000">
	</div>
	<div class="navbar-fixed-top" style="position:absolute; left:25%;top:30%; width:50%;height:10%; text-align: center;opacity: false; background: white" >
		<input style="width:100%;height:100%;" type="button" value="停止录音" onclick="stopRecord()" />
	</div>
	</div>
	
	<!-- 提示登录蒙版 -->
	<div id="alertDiv" style="display:none;text-align:center;line-height:5em; position:absolute;left:15%;top:40%; width: 70%;height:5em;background-color: black;color:white;border-radius:1em;font-size:1.5em;z-index:99999;opacity:0.6;">请输入搜索关键字！</div>
<script>
function cancel(){
	$("#mymodal").modal("toggle");
}
function submit(){
	$("#mymodal").modal("toggle");
	$("#history").remove();
	$("#history_line").remove();
	$("#history_top").remove();
	//$("#del").remove();
	localStorage.setItem(searchStorage.storageName,"[]");
	searchStorage.records = new Array();
}
function init(){
	console.log("${tokenConfig.timestamp}|${tokenConfig.noncestr}|${tokenConfig.signature}")
	wx.config({
		debug:false,
	 	appId:'${appId}',
	 	timestamp:'${tokenConfig.timestamp}',
	 	nonceStr:'${tokenConfig.noncestr}',
	 	signature:'${tokenConfig.signature}',
	 	jsApiList:['scanQRCode','startRecord','stopRecord','stopRecord','translateVoice']
	});
	wx.ready(function() {
		//alert("ready");
		//callScanQRCode();
	});
	wx.error(function(res){
		console.log("err:["+res.errMsg+"]");
		console.log(res);
	});
	
	
	showSearchHistory();
	showHotCat();
	
	var yuyin = "${param.yuyin}";
	if(yuyin){
		document.getElementById("inputText").value= yuyin;    
	    search();
	}
}
function showSearchHistory(){
	if(searchStorage.records.length == 0){
		$("#history").hide();
		$("#history_line").hide();
		$("#history_top").hide();
		return;
	}
	
	var records = searchStorage.records;
	if(records.length > 20){
		var num = records.length - 20; 
		records.splice(20,num);
	}
	var parent = document.getElementById("history");
	var outdiv = null;
	var indiv = null;
	var text = "";
	for(var i=0;i<records.length;i++){
		if(!strExist(records[i].contentId)){
			continue;
		}
		outdiv = document.createElement("div");
		outdiv.id = "outdiv"+i;
		indiv = document.createElement("div");
		indiv.id = "indiv"+i;
		indiv.innerHTML = records[i].contentId;
		outdiv.appendChild(indiv);
		parent.appendChild(outdiv);
		$("#outdiv"+i).addClass("col-xs-6").addClass("history-out");
		$("#indiv"+i).addClass("history-in");
		
		text = records[i].contentId;
		outdiv.setAttribute("onclick", "setSearchValue('"+text+"');");
	}
} 
function showHotCat(){
	var hotCat = new Array();
	hotCat = ${searchHotJson};
	console.log("hotCat:");
	console.log(hotCat);
	//alert(hotCat);
	if(hotCat.length == 0){
		$("#hotCat").hide();
		$("#hotCat_top").hide();
		return;
	}
	
	var parent = document.getElementById("hotCat");
	var indiv = null;
	var text = "";
	for(var i=0;i<hotCat.length;i++){
		outdiv = document.createElement("div");
		outdiv.id = "outdivCat"+i;
		indiv = document.createElement("div");
		indiv.id = "indivCat"+i;
		indiv.innerHTML = hotCat[i].title;
		outdiv.appendChild(indiv);
		parent.appendChild(outdiv);
		$("#outdivCat"+i).addClass("col-xs-12").addClass("hotCat-out");
		$("#indivCat"+i).addClass("hotCat-in");
		
		text = hotCat[i].title;
		outdiv.setAttribute("onclick", "setSearchValue('"+text+"','indivCat"+i+"');");
	}
}
function setSearchValue(text,id){
	$("#"+id).css("color","#16a3b7");
	document.getElementById("inputText").value = text;
	setTimeout(search,500);
}
var tagString = '';
$(".category").each(function(idx,ele){
	var title = ele.innerHTML;
	if(idx>0&& title != '其他'){
		if(tagString == ''){
			tagString = title;
		}else{
			tagString = tagString + ","+title;
		}
	}
});
//vue
var ts = null; 
var vm = new Vue({
	el:"#app",
	data:{
		content : [],
		templatePath:"${_templatePath}",
		resourcePath:"${_resourcePath}",
		contextPath:"${_contextPath}",
		chooseId:"",
		chooseCssName:"",
		currentFcsId:""
	},
	mounted:function() {
		this.$nextTick(function () {
			ts = new TouchScoller(IScollerConfig, getData);
	 	});
	},
	methods:{
		toPlay:function(type,contentCode,prog,title,poster,id,cssName){
			var params = {
					userId:'${EPG_USER_SESSION.userId}',
					type:type,
					code:contentCode,
					prog:'',
					title:title,
					icon:''
				}
			var callback = this.clearFcsId;
			if(arguments.length > 5){
				this.chooseId = id;
				this.chooseCssName = cssName;
				callback = this.changeCss;
			}
			callback();
			play(params,"${personUrl}","searchPage");
		},
		changeCss:function(){
			if(this.currentFcsId != "" && this.currentFcsId.indexOf("zy")!= -1){
				$("#"+this.currentFcsId).removeClass("search-zongyi-fcs").addClass("search-zongyi");
			}else if(this.currentFcsId != ""){
				$("#"+this.currentFcsId).removeClass("col-xs-5ths-ep-fcs").addClass("col-xs-5ths-ep");
			}
			$("#"+this.chooseId).removeClass(this.chooseCssName).addClass(this.chooseCssName+"-fcs");
			this.currentFcsId = this.chooseId;
			//setTimeout("hideAlert('播放请求已发送')",2000);
		},
		clearFcsId:function(){
			if(this.currentFcsId != "" && this.currentFcsId.indexOf("zy")!= -1){
				$("#"+this.currentFcsId).removeClass("search-zongyi-fcs").addClass("search-zongyi");
			}else if(this.currentFcsId != ""){
				$("#"+this.currentFcsId).removeClass("col-xs-5ths-ep-fcs").addClass("col-xs-5ths-ep");
			}
			this.currentFcsId = "";
			//setTimeout("hideAlert('播放请求已发送')",2000);
		},
		showAll:function(divId,seriesCode){
			$("#"+divId).remove();
			$("#"+divId+"_all").show();
			if(this.currentFcsId != "" && this.currentFcsId.indexOf(seriesCode)!= -1 && this.currentFcsId.indexOf("zy") == -1){
				this.changeCss(this.currentFcsId+"_all","col-xs-5ths-ep");
			}
		},
		gotoDetail:function(type,contentCode){
			var path = "${_contextPath}/${_context.siteCode}/${_context.bizCode}/-/-/det/"+type+"/"+contentCode+".wx";
			gotoLink(path,"search_index");
		},
		getDate:getDate
	}
});
var params = {size:6,
		pageindex:1,
		bizCode:"${_context.bizCode}",
		siteCode:"${_context.siteCode}",
		initals:"",
		action:"byKeyWords"};
function getData(pageIndex){
	//标记是否是重新筛选
	var reChoose = false;
	if(arguments.length == 0){
		ts.currentPage = 1;
		ts.firstPage = 1;
		var pageIndex = 1;
		reChoose = true;
		vm.content = [];
		ts.hideEmpty();
	}
	params.pageindex = pageIndex;
	$.ajax({
		method:"get",
		data:params,
		url:"${_contextPath}/api/search/search.json",
		//url:"${_contextPath}/api/search/relation.json",
		async:false,
		success:function(data){
			//console.log(typeof data);
			var result = data;
			console.log("search data:");
			console.log(data);
			getMenuCountAll();
			getMenu();
			var add = result.resultSet;
			if(add && add.length>0){
				//为新增数据增加页数属性pIdx
				for(var i=0;i<add.length;i++){
					add[i].pIdx = pageIndex;
				}
				//增加内容
				if(reChoose  || pageIndex == 1){
					vm.content = add;
					ts.fromStart();
				}else if(pageIndex == ts.currentPage){
					vm.content = vm.content.concat(add);
				}else{
					vm.content = add.concat(vm.content);
					ts.fromStart(2,150);
				}
				//保证可以一直滑
				if(ts.pageCount <= ts.currentPage){ts.pageCount = ts.currentPage + 1};
				//刷新滚动条
				setTimeout(function(){ts.programsScroll.refresh();},500);
			}else{
				if(reChoose){
					//显示结果为空
					ts.newRefresh(0);
				}else{
					//当前是第一页，表示没有内容
					if(ts.currentPage == 1){
						//显示结果为空
						ts.newRefresh(0);
					}else{
						//显示没有更多内容
						ts.pageCount = ts.currentPage;
						ts.hideNoMore();
					}
					
				}
			}
		}
	});
}

function getMenu(){
	$.ajax({
		method:"get",
		data:{initals:params.initals,type:"group"},
		url:"${_contextPath}/api/search/group.json",
		async:false,
		success:function(data){
			console.log("group:");
			console.log(data);
			setCount(data,vm.menuCountAll);
		}
	});
}
function setCount(countJson,countall){
	var all = 0;
	$(".category").each(
		function(idx,ele){
			var title = document.getElementById("liveType_title_"+(idx+1)).value;
			var hasTitle = false;
			if(idx == 0){
				$("#liveType_"+(idx+1)).html("全部("+countall+")");
				//info.menuCount = "全部("+countall+")";
			}else{
				for(var i=0;i<countJson.resultSet.length;i++){
					if(title == countJson.resultSet[i].NAME){
						var text = countJson.resultSet[i].NAME+"("+countJson.resultSet[i].count+")";
						$("#liveType_"+(idx+1)).html(text);
						all = all + parseInt(countJson.resultSet[i].count);
						
						//info.menuCount = info.menuCount + "|" + text;
						hasTitle  = true;
					}
				}
				if(!hasTitle && title != '其他'){
					//info.menuCount = info.menuCount + "|" + title + "(0)";
					$("#liveType_"+(idx+1)).html(title+"(0)");
				}
				if(title == '其他'){
					$("#liveType_"+(idx+1)).html("其他("+(parseInt(countall)-all)+")");
					//info.menuCount = info.menuCount + "|其他("+(parseInt(countall)-all)+")";
				}
			}
		}
	);
	swiper1 = new Swiper("#scroll_menu_swiper", {
	  	 slidesPerView: 'auto',
		 });
}

function getMenuCountAll(){
	$.ajax({
		method:"get",
		data:{initals:params.initals,type:"all"},
		url:"${_contextPath}/api/search/group.json",
		async:false,
		success:function(data){
			console.log("all:");
			console.log(data);
			vm.menuCountAll = data.resultSet[0].count;
			
		}
	});
}
</script>
<%@include file="/sites/weixin/common/bodyEndVm.jsp" %>
</body>
</html>
